<?php
/**
 * AutoCompleteReportItemTest.php
 * 
 * @author Bradley Booms <Bradley.Booms@nsighttel.com>
 * @version Creation Date: Apr 27, 2007
 */

/**
 * AutoCompleteReportItemTest.php class
 * 
 * 
 * 
 * Properties
 * -
 * 
 * @author Bradley Booms <Bradley.Booms@nsighttel.com>
 * @version Modified Date: Apr 27, 2007
 * 
 * Modifications:
 */
class BActiveGoogleMapRandomMarkerTest extends TPage{
	private $markers;
	private $lastMarkerID = 0;
	
	public function mapMove(){
		$bounds = $this->Map->getBounds();
		$markers = $this->getRandomMarkers();
		foreach ($markers as $marker){
			$this->Map->addMarker($marker);
		}
		$this->markers = array_merge($this->markers, $markers);
	}
	
	public function saveState(){
		parent::saveState();
		$this->setViewState('Markers', $this->markers, null);
		$this->setViewState('LastMarkerID', $this->lastMarkerID, null);
	}
	
	public function loadState(){
		parent::loadState();
		if (($this->getIsCallBack()) || ($this->getIsPostBack())){
			$this->markers = $this->getViewState('Markers', null);
			$this->lastMarkerID = $this->getViewState('LastMarkerID', null);
		}
	}
	
	public function onLoad($param){
		parent::onLoad($param);
		foreach ($this->getMarkers() as $marker){
			$this->Map->getControls()->add($marker);
		}
	}
	
	public function getMarkers(){
		if (!$this->markers){
			$this->markers = $this->getRandomMarkers();
		}
		return $this->markers;
	}
	
	public function getRandomMarkers(){
			$markers = array();
			$center = $this->Map->getCenter();
			$bounds = $this->Map->getBounds();
			if ($bounds){
				for ($i=0; $i<10; $i++){
					$marker = prado::createComponent('BActiveGoogleMapMarker');
					$marker->setID('marker'.($this->lastMarkerID + $i));
					$x = rand($bounds[0]*1000, $bounds[1]*1000)/1000;
					$y = rand($bounds[2]*1000, $bounds[3]*1000)/1000;
					$marker->setPoint(array($x, $y));
					$marker->getControls()->add('Marker at ('.$x.', '.$y.')');
					$markers[] = $marker;
				}
			$this->lastMarkerID += 10;
			}
		return $markers;
	}
}
?>